<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Report extends Admin_Controller {
		private $dbconn;

		public function __construct(){  
			parent::__construct();
			$this->dbconn = $this->load->database('default',true);
		}

		public function index(){
			//获取产品列表
			$this->load->model('product_model');
			$productList = $this->product_model->getProduct(array('status'=>1,'platform'=>'IB'),'all','stype DESC');

			//提现、充值
			$this->load->library('Report_Class');
			$cny['balance']		=	$this->report_class->getCnyBalance();
			$cny['withdraw']	=	$this->report_class->getTotalWithdraw();
			$cny['deposit']		=	$this->report_class->getTotalDeposit();
			$cny['userNum']		=	$this->report_class->getUserNum();
			$cny['depositNum']	=	$this->report_class->getTotalDepositNum();
			$cny['onlineNum']	=	$this->report_class->getOnlineNum();
			$cny['inviteNum']	=	$this->report_class->getInviteNum();

			$cny['tradeNum']	=	$this->report_class->getCfdUserNum();
			$cny['cnyTradeNum']	=	$this->report_class->getCfdUserNum("","","","cny");
			$cny['cnyKaiNum']	=	$this->report_class->getCfdKaiNum("","","","cny");
			$cny['ticketKaiNum']=	$this->report_class->getCfdKaiNum("","","","ticket");

			$this->load->library('TicketClass');
			$cny['ticketCny']	=	$this->ticketclass->getBuyTicketCny();

			$cny['fee']		=	$this->report_class->getCfdFee();
			$cny['invite']	=	$this->report_class->getCfdInvite();
			
			//获取总盈亏			
			$cny['history_cny_yk']		=	$this->report_class->getCfdHistoryYk("","","","",'cny');
			$cny['history_ticket_yk']	=	$this->report_class->getCfdHistoryYk("","","","",'ticket');
			$cny['history_yk']			=	bcadd($cny['history_cny_yk'],$cny['history_ticket_yk'],2);
			$chi_data					=	$this->report_class->getCfdChiInfo();

			$cny['chi_cny_bzj']		=	0.00;
			$cny['chi_ticket_bzj']	=	0.00;
			$cny['chi_cny_yk']		=	0.00;
			$cny['chi_ticket_yk']	=	0.00;
			if(!empty($chi_data))foreach($chi_data as $name=>$items){
				$cny['chi_cny_bzj']		=	isset($items['dtype']['cny'])?bcadd($items['dtype']['cny'],$cny['chi_cny_bzj'],2):$cny['chi_cny_bzj'];
				$cny['chi_ticket_bzj']	=	isset($items['dtype']['ticket'])?bcadd($items['dtype']['ticket'],$cny['chi_ticket_bzj'],2):$cny['chi_ticket_bzj'];
				$cny['chi_cny_yk']		=	isset($items['cny_yk'])?bcadd($items['cny_yk'],$cny['chi_cny_yk'],2):$cny['chi_cny_yk'];
				$cny['chi_ticket_yk']	=	isset($items['ticket_yk'])?bcadd($items['ticket_yk'],$cny['chi_ticket_yk'],2):$cny['chi_ticket_yk'];
			}
		
			$cny['deserved_balance']	=	bcsub(bcsub(bcsub(bcsub(bcadd(bcadd($cny['deposit'],$cny['invite'],2),$cny['history_yk'],2),$cny['withdraw'],2),$cny['fee'],2),$cny['chi_cny_bzj'],2),$cny['ticketCny'],2);

			$this->data['page']			=	'report/index';
			$this->data['page_data']	=	$cny;
			$this->load->view('layout',$this->data);
		}

		function today(){
			$this->load->library('Report_Class');
			$balance		=	$this->report_class->getCnyBalance();
			echo "用户余额：".$balance."<br/>";

			$deposit	=	$this->report_class->getTotalDeposit();
			echo "充值：".$deposit."<br/>";

			$withdraw	=	$this->report_class->getTotalWithdraw();
			echo "提现：".$withdraw."<br/>";

			$chi_data				=	$this->report_class->getCfdChiInfo();
			$cny['chi_cny_bzj']		=	0.00;
			$cny['chi_ticket_bzj']	=	0.00;
			$cny['chi_cny_yk']		=	0.00;
			$cny['chi_ticket_yk']	=	0.00;
			if(!empty($chi_data))foreach($chi_data as $name=>$items){
				$cny['chi_cny_bzj']		=	isset($items['dtype']['cny'])?bcadd($items['dtype']['cny'],$cny['chi_cny_bzj'],2):$cny['chi_cny_bzj'];
				$cny['chi_ticket_bzj']	=	isset($items['dtype']['ticket'])?bcadd($items['dtype']['ticket'],$cny['chi_ticket_bzj'],2):$cny['chi_ticket_bzj'];
				$cny['chi_cny_yk']		=	isset($items['cny_yk'])?bcadd($items['cny_yk'],$cny['chi_cny_yk'],2):$cny['chi_cny_yk'];
				$cny['chi_ticket_yk']	=	isset($items['ticket_yk'])?bcadd($items['ticket_yk'],$cny['chi_ticket_yk'],2):$cny['chi_ticket_yk'];
			}
			echo "体验券持仓：".$cny['chi_ticket_bzj']."<br/>";
			echo "CNY持仓：".$cny['chi_cny_bzj']."<br/>";
			
			
			//获取总盈亏			
			$cny['history_cny_yk']		=	$this->report_class->getCfdHistoryYk("","","","",'cny');
			$cny['history_ticket_yk']	=	$this->report_class->getCfdHistoryYk("","","","",'ticket');
			$cny['history_yk']			=	bcadd($cny['history_cny_yk'],$cny['history_ticket_yk'],2);
			echo "体验券盈亏：".bcadd($cny['history_ticket_yk'],$cny['chi_ticket_yk'],2)."<br/>";
			echo "CNY盈亏：".bcadd($cny['history_cny_yk'],$cny['chi_cny_yk'],2)."<br/>";
			
			$cny['userNum']		=	$this->report_class->getUserNum();
			echo "用户总数：".$cny['userNum']."<br/>";

			$cny['tradeNum']	=	$this->report_class->getCfdUserNum();
			$cny['cnyTradeNum']	=	$this->report_class->getCfdUserNum("","","","cny");
			$cny['cnyKaiNum']	=	$this->report_class->getCfdKaiNum("","","","cny");
			$cny['ticketKaiNum']=	$this->report_class->getCfdKaiNum("","","","ticket");
			echo "历史有交易帐户（包括券）：".$cny['tradeNum']."<br/>";
			echo "历史有交易帐户（人民币）：".$cny['cnyTradeNum']."<br/>";
			
			$sdate	=	date("Y-m-d 00:00:00",strtotime("-1 days"));
			$edate	=	date("Y-m-d 23:59:59",strtotime("-1 days"));
			$cny['yestradeNum']	=	$this->report_class->getCfdUserNum($sdate,$edate);
			$cny['yesCnyTradeNum']=	$this->report_class->getCfdUserNum($sdate,$edate,"","cny");
			echo "昨天有交易帐户（包括券）：".$cny['yestradeNum']."<br/>";
			echo "昨天有交易帐户（人民币）：".$cny['yesCnyTradeNum']."<br/>";

			$cny['depositNum']	=	$this->report_class->getTotalDepositNum();
			$cny['inviteNum']	=	$this->report_class->getInviteNum();
			echo "充值人数：".$cny['depositNum']."<br/>";
			echo "上线人数：".$cny['inviteNum']."<br/>";

			$cny['invite']	=	$this->report_class->getCfdInvite();
			echo "累计提成：".$cny['invite']."<br/>";

			echo "开仓手数：".bcadd($cny['cnyKaiNum'],$cny['ticketKaiNum'])."(".$cny['ticketKaiNum'].")<br/>";
			
			$this->load->library('TicketClass');
			$cny['ticketCny']	=	$this->ticketclass->getBuyTicketCny();
			echo "购买体验卷：".$cny['ticketCny']."<br/>";
			echo "796总盈亏（充值－提现－余额－持仓）：".bcsub(bcsub(bcsub($deposit,$withdraw,2),$balance,2),$cny['chi_cny_bzj'],2)."<br/>";
		}

		function test(){
			$this->load->library('Report_Class');
			$user_arr		=	$this->report_class->getUserKaiNum();

			$this->load->library('Invite_Class');
			$invite_arr		=	$this->invite_class->getAllInvite();
			$invite_list	=	array();
			if(!empty($invite_arr)) foreach($invite_arr as $invite){
				$invite_list[$invite['slave']]	=	$invite['master'];
			}
			

			if(!empty($user_arr)) foreach($user_arr as $user){
				$master	=	isset($invite_list[$user['uid']])?$invite_list[$user['uid']]:"";
				if(!$master || $master =='100077'){
					if($master =='100077'){
						echo "UID：".$user['uid']." 开仓数量：".$user['num']. "（".$invite_list[$user['uid']]."）<br/>";
					}else{
						echo "UID：".$user['uid']." 开仓数量：".$user['num']."<br/>";
					}
				}
			}
		}
}